﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using BZLib.Global;

namespace BZLib
{
    namespace Network
    {
        public enum NetMessage
        {
            Null = 0x0000,
            Accept = 0x6163,
            AddPlayer = 0x6170,
            AdminInfo = 0x6169,
            Alive = 0x616c,
            AutoPilot = 0x6175,
            CacheURL = 0x6375,
            CaptureFlag = 0x6366,
            ChatMessage = 0x6d67,
            CustomSound = 0x6373,
            DropFlag = 0x6466,
            Enter = 0x656e,
            Exit = 0x6578,
            FlagUpdate = 0x6675,
            FetchResources = 0x6672,
            GameSettings = 0x6773,
            GameTime = 0x6774,
            GetWorld = 0x6777,
            GMUpdate = 0x676d,
            GrabFlag = 0x6766,
            Killed = 0x6b6c,
//            KrbPrincipal = 0x6b70,
//            KrbTicket = 0x6b74,
            LagPing = 0x7069,
//            LagState = 0x6c73,
            NewRabbit = 0x6e52,
            NegotiateFlags = 0x6e66,
            Pause = 0x7061,
            PlayerInfo = 0x7062,
            PlayerUpdate = 0x7075,
            PlayerUpdateSmall = 0x7073,
            QueryGame = 0x7167,
            QueryPlayers = 0x7170,
            Reject = 0x726a,
            RemovePlayer = 0x7270,
            ReplayReset = 0x7272,
            ShotBegin = 0x7362,
            Score = 0x7363,
            ScoreOver = 0x736f,
            ShotEnd = 0x7365,
//            ServerControl = 0x6f69,
            SuperKill = 0x736b,
            SetVar = 0x7376,
            TimeUpdate = 0x746f,
            Teleport = 0x7470,
            TransferFlag = 0x7466,
            TeamUpdate = 0x7475,
            WantSettings = 0x7773,
            WantWHash = 0x7768,
//            PortalAdd = 0x5061,
//            PortalRemove = 0x5072,
//            PortalUpdate = 0x5075,
            PingCodeReply = 0x0303,
            PingCodeRequest = 0x0404,
            UDPLinkRequest = 0x6f66,
            UDPLinkEstablished = 0x6f67
        }

        public enum NetPlayer
        {
            LastReal = 243,
            Rabbit = 244,
            Observer = 245,
            Purple = 246,
            Blue = 247,
            Green = 248,
            Red = 249,
            Rogue = 250,
            NoTeam = 251,
            Automatic = 252,
            Server = 253,
            All = 254,
            NoPlayer = 255
        }

        public interface IMessageData
        {
            NetMessage GetMessageType();
        }

        public static class Utils
        {
            public static TeamName NetPlayerToTeamName(NetPlayer player)
            {
                if(player < NetPlayer.Rabbit || player > NetPlayer.NoTeam)
                    throw new InvalidOperationException("Not a Team");

                return (TeamName)(250 - (int)player);
            }

            public static NetPlayer TeamNameToNetPlayer(TeamName team)
            {
                return (NetPlayer)(250 - (int)team);
            }
        }
    }
}
